package com.sttg.csp.common.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ThreeDESPassUtil {

	public void outputmenu() {
		System.out.println("Please chhoose the function:");
		System.out.println(" 1. Encrypt a string");
		System.out.println(" 2. Decrypt a string");
		System.out.println(" ----------------------------------");
	}

	public static void main(String[] args) throws Exception {

		ThreeDESPassUtil passUtil = new ThreeDESPassUtil();
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		passUtil.outputmenu();

		while (true) {
			String password, encryotedPassword, decryptedPassword;
			String temp = in.readLine();
			if (temp == null || "".equals(temp)) {
				break;
			}

			switch (temp.charAt(0)) {
				case '1':
					System.out.println("请输入要加密的密码:");
					password = in.readLine();
					encryotedPassword = ThreeDES.encrypt(password);
					System.out.println("加密后的密码: " + encryotedPassword);
					break;
				case '2':
					System.out.println("请输入要解密的密码:");
					encryotedPassword = in.readLine();
					decryptedPassword = ThreeDES.decrypt(encryotedPassword);
					System.out.println("解密后的密码: " + decryptedPassword);
					break;
				default:
					return;
			}

		}
	}
}
